[id].vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <!-- 分类 -->
  3. <div class="main-background">
  4. <!-- SEO -->
  5. <Head>
  6. <Title>厦门市文化遗产保护中心 - {{ articlesData.content.value?.title }}</Title>
  7. <Meta name="description" content="" />
  8. <Meta name="keywords" content="" />
  9. </Head>
  10. <!-- 轮播 -->
  11. <Carousel v-bind="carouselConfig" class="main-header-image carousel-light">
  12. <Slide
  13. v-for="(item, key) in carouselData.content.value"
  14. :key="key"
  15. class="main-header-image"
  16. >
  17. <img class="main-header-image" v-if="item.image" :src="item.image" />
  18. </Slide>
  19. <template #addons>
  20. <Navigation />
  21. <Pagination />
  22. </template>
  23. </Carousel>
  24. <!-- 主要内容 -->
  25. <div class="main-content">
  26. <div class="container">
  27. <div class="row">
  28. <!-- 左侧导航 -->
  29. <div class="col-12 col-sm-12 col-md-4 col-lg-3">
  30. <Sidebar
  31. :title="articlesData.content.value?.channel?.name"
  32. :activeId="articlesData.content.value?.channel?.id"
  33. :showBackUpLevel="articlesData.content.value?.channel?.parent_id !== 0"
  34. :showEmpty="false"
  35. @backUpLevel="router.back()"
  36. />
  37. </div>
  38. <!-- 右侧内容 -->
  39. <div class="col-12 col-sm-12 col-md-8 col-lg-9">
  40. <div class="content">
  41. <div class="section-title">
  42. <h2 class="icon">{{ articlesData.content.value?.channel?.name }}</h2>
  43. <nav aria-label="breadcrumb">
  44. <ol class="breadcrumb">
  45. <li class="breadcrumb-item"><a href="/">首页</a></li>
  46. <li class="breadcrumb-item active" aria-current="page">{{ articlesData.content.value?.channel?.name }}</li>
  47. </ol>
  48. </nav>
  49. </div>
  50. <SimplePageContentLoader :loader="articlesData">
  51. <div v-if="articlesData.content.value" class="news-detail">
  52. <h1>{{ articlesData.content.value.title }}</h1>
  53. <div class="times">
  54. <p class="date">时间:{{ DateUtils.formatDate(new Date(
  55. (articlesData.content.value.publishtime ||
  56. articlesData.content.value.createtime || 0) * 1000), 'yyyy-MM-dd') }}</p>
  57. <!-- <p class="views">浏览量: {{ articlesData.content.value.views }} </p> -->
  58. </div>
  59. <img
  60. v-if="!articlesData.content.value.content && articlesData.content.value.image"
  61. class="head-image"
  62. :src="articlesData.content.value.image"
  63. />
  64. <div class="content" v-html="articlesData.content.value.content">
  65. </div>
  66. <video v-if="articlesData.content.value.video" :src="articlesData.content.value.video" controls></video>
  67. <a-empty v-if="isEmpty"
  68. description="暂无内容"
  69. />
  70. </div>
  71. </SimplePageContentLoader>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </template>
  79. <script setup lang="ts">
  80. import { Carousel, Slide, Pagination, Navigation } from 'vue3-carousel'
  81. import { useSSrSimpleDataLoader } from '@/composeable/SimpleDataLoader';
  82. import { DateUtils } from '@imengyu/imengyu-utils';
  83. import SimplePageContentLoader from '~/components/content/SimplePageContentLoader.vue';
  84. const carouselConfig = {
  85. itemsToShow: 1,
  86. wrapAround: true,
  87. autoplay: 5000,
  88. }
  89. const route = useRoute();
  90. const router = useRouter();
  91. const articleId = parseInt(route.params.id as string);
  92. const carouselData = await useSSrSimpleDataLoader('carousel', async () => {
  93. const res = await $fetch(`/api/ecms/carousel`);
  94. if (!res.status)
  95. throw new Error(res.message);
  96. return res.data;
  97. });
  98. const articlesData = await useSSrSimpleDataLoader('articles' + articleId, async () => {
  99. const res = await $fetch(`/api/ecms/article/${articleId}`, {
  100. method: 'GET',
  101. });
  102. if (!res.status)
  103. throw new Error(res.message);
  104. return res.data;
  105. });
  106. const isEmpty = computed(() => articlesData.content.value
  107. && !articlesData.content.value.content
  108. && !articlesData.content.value.image
  109. && !articlesData.content.value.video);
  110. watch(() => route.query.id, async (newVal, oldVal) => {
  111. if (newVal !== oldVal) {
  112. articlesData.loadData(undefined, true);
  113. }
  114. });
  115. </script>
  116. <style lang="scss">
  117. @use "sass:list";
  118. @use "sass:math";
  119. </style>